package com.itheima.exam.Exam3;

import java.util.*;

//假设一个班级有2间宿舍，一个宿舍可以住4个学生，每个学生有姓名和年龄两个属性，每间宿舍有一个宿舍号，
//要求：创建一个HashMap集合，键是宿舍号，值是宿舍里住的4学生，并遍历Map集合，打印输出每一个宿舍，住了那些学生。
public class Exam3 {
    public static void main(String[] args) {
        Stu s1 = new Stu("小王", 18);
        Stu s2 = new Stu("小张", 19);
        Stu s3 = new Stu("小李", 20);
        Stu s4 = new Stu("小赵", 21);
        Stu[] students = new Stu[]{s1, s2, s3, s4};
        List<Stu> list = new ArrayList<>();
        for (int i = 0; i < students.length; i++) {
            list.add(students[i]);
        }
        Stu s5 = new Stu("小孙", 20);
        Stu s6 = new Stu("小吴", 19);
        Stu s7 = new Stu("小周", 22);
        Stu s8 = new Stu("小郑", 19);
        Stu[] students2 = new Stu[]{s5, s6, s7, s8};
        List<Stu> list2 = new ArrayList<>();
        for (int i = 0; i < students2.length; i++) {
            list2.add(students2[i]);
        }
        Map<String, List> pelple = new HashMap();
        pelple.put("101", list);
        pelple.put("102", list2);
        pelple.entrySet().forEach(entry -> {
            System.out.println("宿舍"+entry.getKey() + "，住的同学是：" + entry.getValue());
        });
    }
}
